export const USER_SET = "USER_SET";
export const USER_CLEAR = "USER_CLEAR";

export default {
	state: {
		userInfo: JSON.parse(uni.getStorage({
			key: 'userInfo',
			success: function(res) {
				console.log(res.data);
			}
		}) || "{}")
	},
	mutations: {
		[USER_SET](state, user) {
			state.userInfo = Object.assign({}, state.userInfo, user);
			uni.setStorage({
				key: 'userInfo',
				data: JSON.stringify(state.userInfo)
			});
		},
		[USER_CLEAR](state) {
			uni.removeStorage({
				key: 'userInfo',
				success: function (res) {
					console.log('success');
				}
			});
			state.userInfo = {};
		}
	},
	actions: {}
}
